package com.dongzhu1428.express.module1.rest;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.dongzhu1428.express.TIP;
import com.dongzhu1428.express.module1.Result;
import com.dongzhu1428.express.module1.dto.controllerDto.Message.GetAllConversationResultDto;
import com.dongzhu1428.express.module1.dto.controllerDto.Message.GetConversationDetailResultDto;
import com.dongzhu1428.express.module1.dto.controllerDto.Message.SendMessageParamDto;
import com.dongzhu1428.express.module1.entity.Message;
import com.dongzhu1428.express.module1.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 消息控制器
 *
 * @author 86188
 * @date 2022/12/09
 */
@RestController
@RequestMapping("/msg")
public class MessageController {

    @Autowired
    MessageService messageService;


    /**
     * 发送消息
     *
     * @param dto dto
     * @return {@link Result}<{@link TIP}>
     */
    @PostMapping("/sendMsg")
    public Result<TIP>  sendMessage(@ModelAttribute SendMessageParamDto dto){
        return  messageService.sendMessage(dto);
    }

    /**
     * 得到所有会话
     * @param userId 用户id
     * @return {@link Result}<{@link GetAllConversationResultDto}>
     */
    @GetMapping("/getAllConversation")
    public Result<GetAllConversationResultDto> getAllConversation(@RequestParam int userId){
        return  messageService.getAllConversation(userId);
    }

    /**
     * 获取会话细节
     * @param userId   用户id
     * @param targetId 目标id
     * @return {@link Result}<{@link GetConversationDetailResultDto}>
     */
    @RequestMapping("getConversationDetail")
    public Result<GetConversationDetailResultDto> getConversationDetail(@RequestParam int userId,@RequestParam int targetId){
        return  messageService.getConversationDetail(userId,targetId);
    }


    /**
     * 所有信息标记为已读
     *
     * @param userId 用户id
     * @return {@link Result}<{@link TIP}>
     */
    @PostMapping("markAllAsRead")
    public Result<TIP>  markAllAsRead(@RequestParam int userId){
        return messageService.markAllAsRead(userId);
    }



}
